#include "custom_sync_action_node.h"

namespace task::node
{
class CustomSyncActionNodeData
{
private:
    friend class CustomSyncActionNode;
    std::shared_ptr<task::AbstractTask> task_;
};
}

namespace task::node
{
CustomSyncActionNode::CustomSyncActionNode(const std::string &name,
                                           const BT::NodeConfiguration &config,
                                           const std::shared_ptr<task::AbstractTask> &task)
    : SyncActionNode(name, config), d(std::make_unique<CustomSyncActionNodeData>())
{
    d->task_ = task;
}
CustomSyncActionNode::~CustomSyncActionNode() = default;

BT::NodeStatus CustomSyncActionNode::tick()
{
    return d->task_->onStart() ? (d->task_->onDone(true), BT::NodeStatus::SUCCESS)
                               : (d->task_->onDone(false), BT::NodeStatus::FAILURE);
}
AbstractTask *CustomSyncActionNode::getTask()
{
    return d->task_.get();
}
std::string CustomSyncActionNode::toString(const std::string &prefix) const
{
    return prefix + type_utils::typeName(*this, {"task", "node"}) + ": " + name();
}
}
